let oBtnLogin = document.getElementById("btnLogin");
let oUserPass = document.getElementById("userpass"); 
let oUserName = document.getElementById("username"); 

oBtnLogin.onclick = function(){
    let xhr = new XMLHttpRequest();
    xhr.open("post","./goodsAndShoppingCart/login.php",true);

    xhr.onreadystatechange = function(){
        if(xhr.readyState==4 && xhr.status==200){
           if(xhr.responseText.trim()=="success"){
               document.getElementById("msg").innerHTML = "登录成功";
               setTimeout(()=>{
                location.href="index.html";
            },2000);
           }else{
               document.getElementById("msg").innerHTML = "登录失败,用户名或者密码错误";
           }
        }
    }

    xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    
    let str = "username="+oUserName.value+"&userpass="+oUserPass.value;
    xhr.send(str);

}